﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Platform.Migrations
{
    /// <inheritdoc />
    public partial class modify_table_PubItem_grant : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_MainPatnBaseInfo_MainPatnMasterIdx_PatnMasterIdxId",
                table: "MainPatnBaseInfo");

            migrationBuilder.DropForeignKey(
                name: "FK_MainPatnCardInfo_MainPatnMasterIdx_PatnMasterIdxId",
                table: "MainPatnCardInfo");

            migrationBuilder.DropPrimaryKey(
                name: "PK_MainTcmsympDict",
                table: "MainTcmsympDict");

            migrationBuilder.DropPrimaryKey(
                name: "PK_MainTcmDiseDict",
                table: "MainTcmDiseDict");

            migrationBuilder.DropPrimaryKey(
                name: "PK_MainPatnMasterIdx",
                table: "MainPatnMasterIdx");

            migrationBuilder.DropPrimaryKey(
                name: "PK_MainPatnCardInfo",
                table: "MainPatnCardInfo");

            migrationBuilder.DropPrimaryKey(
                name: "PK_MainPatnBaseInfo",
                table: "MainPatnBaseInfo");

            migrationBuilder.DropPrimaryKey(
                name: "PK_MainClncDiagDict",
                table: "MainClncDiagDict");

            migrationBuilder.RenameTable(
                name: "MainTcmsympDict",
                newName: "SdTcmsympDict");

            migrationBuilder.RenameTable(
                name: "MainTcmDiseDict",
                newName: "SdTcmDiseDict");

            migrationBuilder.RenameTable(
                name: "MainPatnMasterIdx",
                newName: "SdPatnMasterIdx");

            migrationBuilder.RenameTable(
                name: "MainPatnCardInfo",
                newName: "SdPatnCardInfo");

            migrationBuilder.RenameTable(
                name: "MainPatnBaseInfo",
                newName: "SdPatnBaseInfo");

            migrationBuilder.RenameTable(
                name: "MainClncDiagDict",
                newName: "SdClncDiagDict");

            migrationBuilder.RenameIndex(
                name: "IX_MainPatnCardInfo_PatnMasterIdxId",
                table: "SdPatnCardInfo",
                newName: "IX_SdPatnCardInfo_PatnMasterIdxId");

            migrationBuilder.RenameIndex(
                name: "IX_MainPatnBaseInfo_PatnMasterIdxId",
                table: "SdPatnBaseInfo",
                newName: "IX_SdPatnBaseInfo_PatnMasterIdxId");

            migrationBuilder.AddPrimaryKey(
                name: "PK_SdTcmsympDict",
                table: "SdTcmsympDict",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_SdTcmDiseDict",
                table: "SdTcmDiseDict",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_SdPatnMasterIdx",
                table: "SdPatnMasterIdx",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_SdPatnCardInfo",
                table: "SdPatnCardInfo",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_SdPatnBaseInfo",
                table: "SdPatnBaseInfo",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_SdClncDiagDict",
                table: "SdClncDiagDict",
                column: "Id");

            migrationBuilder.CreateTable(
                name: "SdPubItem",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    PubItemCatgeCodg = table.Column<string>(type: "text", nullable: false),
                    PubItemCatgeName = table.Column<string>(type: "text", nullable: false),
                    PubItemCodg = table.Column<string>(type: "text", nullable: false),
                    PubItemName = table.Column<string>(type: "text", nullable: false),
                    Spec = table.Column<string>(type: "text", nullable: false),
                    Unt = table.Column<string>(type: "text", nullable: false),
                    Pric = table.Column<decimal>(type: "numeric", nullable: false),
                    Pinyincode = table.Column<string>(type: "text", nullable: true),
                    Wubicode = table.Column<string>(type: "text", nullable: true),
                    PriceCode = table.Column<string>(type: "text", nullable: true),
                    ChkFlag = table.Column<bool>(type: "boolean", nullable: false),
                    DisabFlag = table.Column<bool>(type: "boolean", nullable: false),
                    SrtNo = table.Column<int>(type: "integer", nullable: false),
                    AgmtItemFlag = table.Column<bool>(type: "boolean", nullable: false),
                    RxFlag = table.Column<bool>(type: "boolean", nullable: false),
                    DrordFlag = table.Column<bool>(type: "boolean", nullable: false),
                    NurseExecFlag = table.Column<bool>(type: "boolean", nullable: false),
                    DrugFlag = table.Column<bool>(type: "boolean", nullable: false),
                    ExamFlag = table.Column<bool>(type: "boolean", nullable: false),
                    TestFlag = table.Column<bool>(type: "boolean", nullable: false),
                    HiApprFlag = table.Column<bool>(type: "boolean", nullable: false),
                    OrdrFlag = table.Column<bool>(type: "boolean", nullable: false),
                    SubTitle = table.Column<string>(type: "text", nullable: true),
                    Descr = table.Column<string>(type: "text", nullable: true),
                    Icon = table.Column<string>(type: "text", nullable: true),
                    ProfilePhoto = table.Column<string>(type: "text", nullable: true),
                    ImgConts = table.Column<string>(type: "text", nullable: true),
                    ConsultTel = table.Column<string>(type: "text", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uuid", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SdPubItem", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "SdAgmtItem",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    PubItemId = table.Column<Guid>(type: "uuid", nullable: false),
                    Cnt = table.Column<float>(type: "real", nullable: false),
                    SrtNo = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SdAgmtItem", x => x.Id);
                    table.ForeignKey(
                        name: "FK_SdAgmtItem_SdPubItem_PubItemId",
                        column: x => x.PubItemId,
                        principalTable: "SdPubItem",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "SdPubItemAssocChrgitmType",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    PubItemId = table.Column<Guid>(type: "uuid", nullable: false),
                    ClncChrgitmTypeCode = table.Column<string>(type: "text", nullable: false),
                    ClncChrgitmTypeName = table.Column<string>(type: "text", nullable: false),
                    HiChrgitmTypeCode = table.Column<string>(type: "text", nullable: true),
                    HiChrgitmTypeName = table.Column<string>(type: "text", nullable: true),
                    MedcasChrgitmTypeCode = table.Column<string>(type: "text", nullable: true),
                    MedcasChrgitmTypeName = table.Column<string>(type: "text", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SdPubItemAssocChrgitmType", x => x.Id);
                    table.ForeignKey(
                        name: "FK_SdPubItemAssocChrgitmType_SdPubItem_PubItemId",
                        column: x => x.PubItemId,
                        principalTable: "SdPubItem",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "SdPubItemBilgGrant",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    PubItemId = table.Column<Guid>(type: "uuid", nullable: false),
                    ProviderKey = table.Column<string>(type: "text", nullable: false),
                    ProviderName = table.Column<string>(type: "text", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SdPubItemBilgGrant", x => x.Id);
                    table.ForeignKey(
                        name: "FK_SdPubItemBilgGrant_SdPubItem_PubItemId",
                        column: x => x.PubItemId,
                        principalTable: "SdPubItem",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "SdPubItemExecGrant",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    PubItemId = table.Column<Guid>(type: "uuid", nullable: false),
                    ProviderKey = table.Column<string>(type: "text", nullable: false),
                    ProviderName = table.Column<string>(type: "text", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SdPubItemExecGrant", x => x.Id);
                    table.ForeignKey(
                        name: "FK_SdPubItemExecGrant_SdPubItem_PubItemId",
                        column: x => x.PubItemId,
                        principalTable: "SdPubItem",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_SdAgmtItem_PubItemId",
                table: "SdAgmtItem",
                column: "PubItemId");

            migrationBuilder.CreateIndex(
                name: "IX_SdPubItemAssocChrgitmType_PubItemId",
                table: "SdPubItemAssocChrgitmType",
                column: "PubItemId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_SdPubItemBilgGrant_PubItemId",
                table: "SdPubItemBilgGrant",
                column: "PubItemId");

            migrationBuilder.CreateIndex(
                name: "IX_SdPubItemExecGrant_PubItemId",
                table: "SdPubItemExecGrant",
                column: "PubItemId");

            migrationBuilder.AddForeignKey(
                name: "FK_SdPatnBaseInfo_SdPatnMasterIdx_PatnMasterIdxId",
                table: "SdPatnBaseInfo",
                column: "PatnMasterIdxId",
                principalTable: "SdPatnMasterIdx",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_SdPatnCardInfo_SdPatnMasterIdx_PatnMasterIdxId",
                table: "SdPatnCardInfo",
                column: "PatnMasterIdxId",
                principalTable: "SdPatnMasterIdx",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_SdPatnBaseInfo_SdPatnMasterIdx_PatnMasterIdxId",
                table: "SdPatnBaseInfo");

            migrationBuilder.DropForeignKey(
                name: "FK_SdPatnCardInfo_SdPatnMasterIdx_PatnMasterIdxId",
                table: "SdPatnCardInfo");

            migrationBuilder.DropTable(
                name: "SdAgmtItem");

            migrationBuilder.DropTable(
                name: "SdPubItemAssocChrgitmType");

            migrationBuilder.DropTable(
                name: "SdPubItemBilgGrant");

            migrationBuilder.DropTable(
                name: "SdPubItemExecGrant");

            migrationBuilder.DropTable(
                name: "SdPubItem");

            migrationBuilder.DropPrimaryKey(
                name: "PK_SdTcmsympDict",
                table: "SdTcmsympDict");

            migrationBuilder.DropPrimaryKey(
                name: "PK_SdTcmDiseDict",
                table: "SdTcmDiseDict");

            migrationBuilder.DropPrimaryKey(
                name: "PK_SdPatnMasterIdx",
                table: "SdPatnMasterIdx");

            migrationBuilder.DropPrimaryKey(
                name: "PK_SdPatnCardInfo",
                table: "SdPatnCardInfo");

            migrationBuilder.DropPrimaryKey(
                name: "PK_SdPatnBaseInfo",
                table: "SdPatnBaseInfo");

            migrationBuilder.DropPrimaryKey(
                name: "PK_SdClncDiagDict",
                table: "SdClncDiagDict");

            migrationBuilder.RenameTable(
                name: "SdTcmsympDict",
                newName: "MainTcmsympDict");

            migrationBuilder.RenameTable(
                name: "SdTcmDiseDict",
                newName: "MainTcmDiseDict");

            migrationBuilder.RenameTable(
                name: "SdPatnMasterIdx",
                newName: "MainPatnMasterIdx");

            migrationBuilder.RenameTable(
                name: "SdPatnCardInfo",
                newName: "MainPatnCardInfo");

            migrationBuilder.RenameTable(
                name: "SdPatnBaseInfo",
                newName: "MainPatnBaseInfo");

            migrationBuilder.RenameTable(
                name: "SdClncDiagDict",
                newName: "MainClncDiagDict");

            migrationBuilder.RenameIndex(
                name: "IX_SdPatnCardInfo_PatnMasterIdxId",
                table: "MainPatnCardInfo",
                newName: "IX_MainPatnCardInfo_PatnMasterIdxId");

            migrationBuilder.RenameIndex(
                name: "IX_SdPatnBaseInfo_PatnMasterIdxId",
                table: "MainPatnBaseInfo",
                newName: "IX_MainPatnBaseInfo_PatnMasterIdxId");

            migrationBuilder.AddPrimaryKey(
                name: "PK_MainTcmsympDict",
                table: "MainTcmsympDict",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_MainTcmDiseDict",
                table: "MainTcmDiseDict",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_MainPatnMasterIdx",
                table: "MainPatnMasterIdx",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_MainPatnCardInfo",
                table: "MainPatnCardInfo",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_MainPatnBaseInfo",
                table: "MainPatnBaseInfo",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_MainClncDiagDict",
                table: "MainClncDiagDict",
                column: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_MainPatnBaseInfo_MainPatnMasterIdx_PatnMasterIdxId",
                table: "MainPatnBaseInfo",
                column: "PatnMasterIdxId",
                principalTable: "MainPatnMasterIdx",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainPatnCardInfo_MainPatnMasterIdx_PatnMasterIdxId",
                table: "MainPatnCardInfo",
                column: "PatnMasterIdxId",
                principalTable: "MainPatnMasterIdx",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
